//
//  ShowShareView.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/19.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "ShowShareView.h"
#import "TButton.h"

@interface ShowShareView()

@property (nonatomic,weak) UIView *shareView;
@property (nonatomic,weak) UILabel *titleLab;
@property (nonatomic,strong) ClickBlock block;

@end

@implementation ShowShareView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        [window addSubview:self];
        
        UIView *shareView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenH, ScreenW, 170)];
        shareView.backgroundColor = [UIColor whiteColor];
        [self addSubview:shareView];
        self.shareView = shareView;
        
        NSArray *titleArray = [[NSArray alloc] initWithObjects:@"微信", @"朋友圈", @"QQ", nil];
        NSArray *iconArray = [[NSArray alloc] initWithObjects:@"btn_share_wx", @"btn_share_wxq", @"btn_share_qq", nil];
        NSMutableArray *itemArray = [NSMutableArray array];
        CGFloat width = ScreenW/3.0;
        for (int i = 0; i < titleArray.count; i++) {
            NSString *title = titleArray[i];
            NSString *icon = iconArray[i];
            TButton *button = [[TButton alloc]initWithFrame:CGRectMake(width*i, (shareView.height-width)/2+20, width, width)];
            button.type = ButtonType_TB;
            button.tag = i;
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [button setTitle:title forState:UIControlStateNormal];
            [button setImage:GetImage(icon) forState:UIControlStateNormal];
            [button addTarget:self action:@selector(clickShare:) forControlEvents:UIControlEventTouchUpInside];
            [shareView addSubview:button];
            [itemArray addObject:button];
        }
        
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, ScreenW, 20)];
        titleLab.text = @"分享到";
        titleLab.textColor = RGBColorOne(160);
        titleLab.backgroundColor = [UIColor clearColor];
        titleLab.font = [UIFont systemFontOfSize:14];
        titleLab.textAlignment = NSTextAlignmentCenter;
        [shareView addSubview:titleLab];
        self.titleLab = titleLab;
    }
    return self;
}
//分享点击
- (void)clickShare:(UIButton *)btn
{
    if (self.block) {
        self.block((ShareType)btn.tag);
    }
}

- (void)dismiss
{
    [self removeFromSuperview];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self animatedHide];
}
//显示调用
- (void)showshareView:(ClickBlock)block
{
    self.block = block;
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.shareView.y = ScreenH-self.shareView.height;
    } completion:nil];
}

- (void)animatedHide
{
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.shareView.y = ScreenH;
    } completion:^(BOOL finished) {
        [self dismiss];
    }];
}

@end
